package com.swz.dcrm.ui.monthly;


import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.swz.dcrm.adpter.GlobalAdapter;
import com.swz.dcrm.model.BaseResponse;
import com.swz.dcrm.model.MonthlyGoal;
import com.swz.dcrm.ui.base.BaseFragment;
import com.swz.dcrm.R;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;
import androidx.navigation.fragment.NavHostFragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.widget.ProgressBar;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.OnClick;

import com.swz.dcrm.R;
import com.swz.dcrm.ui.viewmodel.AnalyzeViewModel;
import com.swz.dcrm.util.CustomDecoration;

import javax.inject.Inject;

/**
 * A simple {@link Fragment} subclass.
 */
public class MonthlyGoalFragment extends BaseFragment {


    @BindView(R.id.tv_rate1)
    TextView tvRate1;
    @BindView(R.id.tv_rate2)
    TextView tvRate2;
    @BindView(R.id.tv_rate3)
    TextView tvRate3;
    @BindView(R.id.progress_bar1)
    ProgressBar progressBar1;
    @BindView(R.id.progress_bar2)
    ProgressBar progressBar2;
    @BindView(R.id.progress_bar3)
    ProgressBar progressBar3;
    @BindView(R.id.tv_actual_build_count)
    TextView tvActualBuildCount;
    @BindView(R.id.tv_actual_order_count)
    TextView tvActualOrderCount;
    @BindView(R.id.tv_actual_delivery_count)
    TextView tvActualDeliveryCount;
    @BindView(R.id.tv_goal_count)
    TextView tvBuildGoalCount;
    @BindView(R.id.tv_order_goal_count)
    TextView tvOrderGoalCount;
    @BindView(R.id.tv_delivery_goal_count)
    TextView tvDeliveryGoalCount;
    @Inject
    AnalyzeViewModel analyzeViewModel;
    public static MonthlyGoalFragment newInstance() {

        return new MonthlyGoalFragment();
        // Required empty public constructor
    }

    @Override
    public void onLoadRetry() {
        if (!isNetworkConnected(getContext())){
            mHolder.showLoadingStatus(GlobalAdapter.NET_ERROR);
            return;
        }
        analyzeViewModel.getMonthlyGoal().observe(this, observer);
    }

    Observer observer=new Observer<BaseResponse<MonthlyGoal>>() {
        @Override
        public void onChanged(BaseResponse<MonthlyGoal> monthlyGoalBaseResponse) {
            if(monthlyGoalBaseResponse.isSuccess()){
                MonthlyGoal monthlyGoal=monthlyGoalBaseResponse.getData();
                tvRate1.setText(monthlyGoal.getBuildFileItem().getRate()+"%");
                tvRate2.setText(monthlyGoal.getOrderCarItem().getRate()+"%");
                tvRate3.setText(monthlyGoal.getDeliveryCarItem().getRate()+"%");
                progressBar1.setProgress(Double.valueOf(monthlyGoal.getBuildFileItem().getRate()).intValue());
                progressBar2.setProgress(Double.valueOf(monthlyGoal.getOrderCarItem().getRate()).intValue());
                progressBar3.setProgress(Double.valueOf(monthlyGoal.getDeliveryCarItem().getRate()).intValue());
                tvActualBuildCount.setText(monthlyGoal.getBuildFileItem().getActualCount()+"");
                tvActualOrderCount.setText(monthlyGoal.getOrderCarItem().getActualCount()+"");
                tvActualDeliveryCount.setText(monthlyGoal.getDeliveryCarItem().getActualCount()+"");
                tvBuildGoalCount.setText(monthlyGoal.getBuildFileItem().getTargetCount()+"");
                tvOrderGoalCount.setText(monthlyGoal.getOrderCarItem().getTargetCount()+"");
                tvDeliveryGoalCount.setText(monthlyGoal.getDeliveryCarItem().getTargetCount()+"");

            }
        }
    };
    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        onLoadRetry();
    }

    @Override
    public int layoutId() {
        return R.layout.fragment_monthly_goal;
    }

    @Override
    public boolean initView() {
        getDigger().inject(this);
        return false;
    }


}
